// /*
//  * @Author: WanYiMing
//  * @Date:2024-07-05-11:16
//  * @Description:
//  */

using System;
using Code.GameLogic.XianJian.Element.JianQiAction;
using UnityEngine;

namespace Code.GameLogic.XianJian.Element
{
    public class JianQiBehaviour : MonoBehaviour
    {
        private Action<GameObject> _hitTarget;

        private AbsJianQiAction _absJianQiAction;

        private JianQiActionData _jianQiActionData;


        public void ActiveBehaviour(Action<GameObject> hitTarget, GameObject target, float speed,
            AbsJianQiAction absJianQiAction)
        {
            _hitTarget = hitTarget;
            _absJianQiAction = absJianQiAction;
            _absJianQiAction.InitAction(new JianQiActionData(target, gameObject, speed));
            _absJianQiAction.ActionStart();
        }


        public void Update()
        {
            if (_jianQiActionData is not null)
            {
                _jianQiActionData.ActiveTime += Time.deltaTime;
            }

            if (!_absJianQiAction.ActionHolding())
            {
                _absJianQiAction.ActionExit();
                Hit();
            }
        }


        private void Hit()
        {
            _hitTarget(gameObject);
        }
    }
}